package com.putao.album.guide.anim;

import com.google.gson.Gson;
import com.putao.album.util.Loger;
import com.putao.album.util.ResourcesHelper;
import com.putao.album.util.StringHelper;

import java.util.ArrayList;

/**
 * Created by jidongdong on 15/5/11.
 */
public class GuideAnmiUtil {

    private static ConfigInfo mConfigInfo;

    public static ConfigInfo getConfigInfo() {
        String config = getGuideConfigText();
        if (!StringHelper.isEmpty(config) && mConfigInfo == null) {
            try {
                mConfigInfo = new Gson().fromJson(config, ConfigInfo.class);
            } catch (Exception e) {
                Loger.d("config info error::" + e.getMessage());
                e.printStackTrace();
            }
        }
        return mConfigInfo;
    }

    public static ArrayList<ConfigInfo.Elements> getSenceElements(int senceid) {
        if (getConfigInfo() != null) {
            ArrayList<ConfigInfo.SenceItem> senceItems = getConfigInfo().getSences();
            for (int i = 0; i < senceItems.size(); i++) {
                ConfigInfo.SenceItem item = senceItems.get(i);
                if (item.getSenceid() == senceid) {
                    return item.getElements();
                }
            }
        }
        return null;
    }


    static String getGuideConfigText() {
        return ResourcesHelper.getAssetTextFile("guide_ainm_config");
    }
}
